<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我要开店</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>res/hjt/layui/css/layui.css"
	media="all">
<base href="<%=basePath%>">
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>开店信息</legend>
	</fieldset>

	<form class="layui-form" action="<%=basePath%>merchant/saveAdd.action" method="post">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">店铺名称</label>
				<div class="layui-input-inline">
					<input type="text" name="merchantName" id="merchantName" required
						lay-verify="required" placeholder="店铺名称" autocomplete="off"
						class="layui-input" maxlength="10">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">店长账号</label>
				<div class="layui-input-inline">
					<input type="text" name="manUser" id="manUser" required
						lay-verify="required" maxlength="11" placeholder="后台管理员账号"
						autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">商家电话</label>
				<div class="layui-input-inline">
					<input type="text" onblur="phone()" name="merchantPhone" id="merchantPhone" required
						lay-verify="required" placeholder="商家电话" autocomplete="off"
						class="layui-input" >
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">店长密码</label>
				<div class="layui-input-inline">
					<input type="password" name="manPwd" id="manPwd" required
						lay-verify="required" maxlength="11" placeholder="后台管理员密码"
						autocomplete="off" class="layui-input" maxlength="10">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
					<label class="layui-form-label">餐馆类型</label>
					<div class="layui-input-inline">
						<select name="typeId" lay-verify="required" lay-search="" id="typeId">
							<option value="">直接选择或搜索选择</option>
							<option value="1">美食</option>
							<option value="2">早餐</option>
							<option value="3">午餐</option>
						</select>
					</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">身份证号</label>
				<div class="layui-input-block">
					<input onblur="card()" type="text" name="manCardid" id="manCardid"
						lay-verify="required" placeholder="请输入身份证" maxlength="18" autocomplete="off"
						class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-demo">
				
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">餐馆地址</label>
				<div class="layui-input-inline">
					<select name="quiz1"  lay-verify="required" required lay-filter="business">
						<option value="">请选择省</option>
						<option value="浙江省">浙江省</option>
						<option value="江西省">江西省</option>
						<option value="福建省">福建省</option>
					</select>
				</div>
				<div class="layui-input-inline">
					<select name="quiz2" lay-verify="required" required lay-filter="business">
						<option value="">请选择市</option>
						<option value="杭州市">杭州市</option>
						<option value="宁波市">宁波市</option>
						<option value="温州市">温州市</option>
						<option value="台州市">台州市</option>
						<option value="绍兴市">绍兴市</option>
					</select>
				</div>
				<div class="layui-input-inline">
					<select name="quiz3"  lay-verify="required" required lay-filter="business">
						<option value="">请选择县/区</option>
						<option value="西湖区">西湖区</option>
						<option value="余杭区">余杭区</option>
					</select>
				</div>
				<input type="hidden" id="merchantSite" name="merchantSite">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">详细地址</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" lay-verify="required" required class="layui-textarea" maxlength="20" name="merchantCredit"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-demo">
				
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="submit" class="layui-btn" lay-submit=""
					lay-filter="Add" value="提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	<script src="<%=basePath %>res/hjt/layui/lay/modules/tree.js"></script>
	<script src="<%=basePath%>res/wzw/layui/layui.js"></script>
	<script type="text/javascript" src="res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="<%=basePath%>js/jquery-1.10.2.js"></script>

	
	<script type="text/javascript">
		
	function phone(){
	    var phone = document.getElementById('merchantPhone').value;
	    if(!(/^1[34578]\d{9}$/.test(phone))){
	        /*alert("手机号码有误，请重新填写"); */
	       $("#merchantPhone").attr("placeholder","手机号码格式不正确");
	       document.getElementById('merchantPhone').value="";
	       return false;
	    }
	    var url = "<%=basePath%>merchant/findMerchantByPhone.action";
	    var data={"phone":phone}
		$.post(url,data,function(mes){
			alert(mes.msg);
			if(mes.msg=="no"){
				 $("#merchantPhone").attr("placeholder","手机号码已被使用");
				 document.getElementById('merchantPhone').value="";
			       return false;
			}else{
				
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
	}
	
	
	function card(){ 
		// 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X 
		var card = document.getElementById('manCardid').value;
		if(!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card))){ 
			/*alert("身份证格式不正确");*/
			$("#manCardid").attr("placeholder","身份证格式不正确");
		    document.getElementById('manCardid').value="";
			return false; 
		} 
	}
	
		layui.use('form', function(){
			  var form = layui.form
			  ,layer = layui.layer
			  ,$ = layui.$;
			  form.on('submit(Add)',function(){
				 
				  parent.location.reload(); // 父页面刷新
			  });
			  var quiz1 = "";
			  var quiz2 = "";
			  var quiz3 = "";
			  form.on('select(business)', function(data){
				  var selectName = $(data.elem).attr("name");
				  if(selectName == "quiz1"){
					  quiz1 = data.value;
				  }else if(selectName == "quiz2"){
					  quiz2 = data.value;
				  }else if(selectName == "quiz3"){
					  quiz3 = data.value;
					  $("#merchantSite").val(quiz1+"-"+quiz2+"-"+quiz3);
				  }
			});
		});
		
	</script>
</body>
</html>